package top.infopub.mgr.fia.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import top.infopub.generic.GenericDao;
import top.infopub.generic.GenericServiceImpl;
import top.infopub.mgr.fia.dao.SuperProfitDao;
import top.infopub.mgr.fia.domain.SuperProfitDomain;
import top.infopub.mgr.fia.service.SuperProfitService;
import top.infopub.mgr.fia.vo.SuperProfitVo;
import top.infopub.model.fia.SuperProfit;
import top.infopub.security.util.SessionUserUtils;
import top.infopub.security.vo.AuthorizationVO;
import top.infopub.tdp.sys.service.CodeGeneratorConfigService;
import top.infopub.tdp.util.BizParaUtil;
import top.infopub.util.IdFactory;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@Service
public class SuperProfitServiceImpl extends GenericServiceImpl<SuperProfit, String> implements
		SuperProfitService {

	@Autowired
	private SuperProfitDao superProfitDao;
	
	@Override
	public GenericDao<SuperProfit, String> getDao() {
		return superProfitDao;
	}
	
	@Autowired
    private CodeGeneratorConfigService codeGeneratorConfigService;


    @Override
    public Page<SuperProfitDomain> selectPageByDomainWhere(Page<SuperProfitDomain> page,
                                                            SuperProfitVo superProfitVo) {
        
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        Page<SuperProfitDomain> sPfit = superProfitDao.selectByDomainWhere(superProfitVo);
        return sPfit;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveSpFit(SuperProfit superProfit) {
        String codes = codeGeneratorConfigService.generatorCode("fia_super_profit");
        String hrOrgBillId = BizParaUtil.get("super_org_id");
        AuthorizationVO vo = SessionUserUtils.getSessionAttributeForUserDtl();
        
        superProfit.setId(IdFactory.getUUIDUpper());
        superProfit.setCodes(codes);
        superProfit.setHrOrgBillId(hrOrgBillId);
        superProfit.setAddBy(vo.getId());
        superProfit.setAddTime(top.infopub.mgr.util.DateUtils.getCurrentDateTime());
        superProfit.setUptBy(vo.getId());
        superProfit.setUptTime(top.infopub.mgr.util.DateUtils.getCurrentDateTime());
        superProfit.setState(1); //已登记
        superProfitDao.insert(superProfit);
        
    }

    @Override
    public Boolean changeState(String id,  int state) {
        return  superProfitDao.changeState(id,state);
    }

    @Override
    public SuperProfitDomain queryDomainById(String id) {
        return superProfitDao.queryDomainById(id);
    }


}